package com.shycloud.mido.member.service.impl;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shycloud.mido.common.core.exception.BusinessException;
import com.shycloud.mido.member.api.entity.BasicGoodsInfo;
import com.shycloud.mido.member.api.entity.BasicProductInfo;
import com.shycloud.mido.member.api.entity.BasicShoppingBanner;
import com.shycloud.mido.member.api.vo.ShoppingRecommendGoodsVO;
import com.shycloud.mido.member.mapper.BasicGoodsInfoMapper;
import com.shycloud.mido.member.mapper.BasicProductInfoMapper;
import com.shycloud.mido.member.mapper.BasicShoppingBannerMapper;
import com.shycloud.mido.member.service.BasicShoppingBannerService;

import lombok.AllArgsConstructor;

@Service
@AllArgsConstructor
public class BasicShoppingBannerServiceImpl extends ServiceImpl<BasicShoppingBannerMapper, BasicShoppingBanner> implements BasicShoppingBannerService {

	/** 商品信息 mapper */
	private BasicGoodsInfoMapper goodsInfoMapper;
	/** 商品类别 mapper */
	private BasicProductInfoMapper productInfoMapper;
	/** 后台商品设置 mapper */
	private BasicShoppingBannerMapper shoppingBannerMapper;

	@Override
	public ShoppingRecommendGoodsVO getGoodsById(Integer id) {

		ShoppingRecommendGoodsVO res = new ShoppingRecommendGoodsVO();

		//查询商品信息
		BasicGoodsInfo basicGoodsInfo = goodsInfoMapper.selectById(id);

		if (basicGoodsInfo == null) {
			throw new BusinessException("ID不存在");
		}

		res.setGoodsId(id);

		res.setGoodsName(basicGoodsInfo.getName());

		BasicProductInfo basicProductInfo = productInfoMapper.selectById(basicGoodsInfo.getProductId());

		res.setGoodsType(basicProductInfo.getName());

		res.setPrice(basicGoodsInfo.getGoodsPrice());

		return res;

	}

	@Override
	public ShoppingRecommendGoodsVO getCollectionById(Integer id) {
		return shoppingBannerMapper.getCollectionById(id);
	}
}
